// screenshot.js
const puppeteer = require('puppeteer');
const fs = require('fs');

(async () => {
    const htmlFilePath = process.argv[2]; // 第一个参数：HTML路径
    const outputImagePath = process.argv[3]; // 第二个参数：图片输出路径

    if (!htmlFilePath || !outputImagePath) {
        console.error('Usage: node screenshot.js <htmlFilePath> <outputImagePath>');
        process.exit(1);
    }

    const html = fs.readFileSync(htmlFilePath, 'utf-8');
    const browser = await puppeteer.launch({ headless: "new" });
    const page = await browser.newPage();

    await page.setContent(html, { waitUntil: 'networkidle0' });
    await page.setViewport({ width: 800, height: 600 });

    await page.screenshot({ path: outputImagePath, fullPage: true });
    await browser.close();
})();
